{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from PIL import Image\n",
    "import cv2\n",
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "def convert(img):\n",
    "    anno_map = np.asarray(img)\n",
    "    anno_map[anno_map == 4] = 4\n",
    "\n",
    "    R = anno_map.copy()   # 红色通道\n",
    "    R[R == 1] = 0\n",
    "    R[R == 2] = 0\n",
    "    R[R == 3] = 255\n",
    "\n",
    "    G = anno_map.copy()   # 绿色通道\n",
    "    G[G == 1] = 0\n",
    "    G[G == 2] = 255\n",
    "    G[G == 3] = 0\n",
    "\n",
    "    B = anno_map.copy()   # 蓝色通道\n",
    "    B[B == 1] = 255\n",
    "    B[B == 2] = 0\n",
    "    B[B == 3] = 0\n",
    "    return np.dstack((R,G,B))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7f466e5e29d0>"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAQYAAAD8CAYAAACVSwr3AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAASjElEQVR4nO3df7BcZX3H8ffn3gtRQmxJkRghlaCxNThttGlqiz+rCNKxQStMbEdjByb+gVprOxqwrdrWqfiLceqPMVZqtBbMVCix7aiIWsZOFRIaIIEiQaJckkmq2AadEcm93/7xnJXNPbv37t09Z885u5/XzM7unj179nv37n72Oec85zmKCMzM2k1UXYCZ1Y+DwcxyHAxmluNgM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Oz90vaWnU9c0k6IOnO7NDyXdm05ZJulHRvdj30sxlmx6cckbS3bVrXuqo8FL5LrbU7bH+eIQZq9b4OZSiEiKjsQhrH9z7gLNLAXLcDa6usqUONB4BT50x7L7A1u70VuLKCup4PPBvYu1BdpFOq3E4axG119p5PVlzrO4E/7TBvZbUCK4FnZ7eXAd/O6qnV+zpPnYW9p1W3GDYA+yPiOxHxU+Ba0mHbdbcR2J7d3g5cOOwCIuJm0mBt7brVVemh8F1q7aayWqP7EAO1el/nqbObRddZdTD0dIh2xQL4sqTdkrZk01ZExCFI/yTgtMqqO163uur6Pvd92H7Z5gwxUNv3tcihENpVHQw9HaJdsXMi4tnAy4DLJD2/6oL6UMf3eaDD9svUYYiBrrN2mDa0WoseCqFd1cFQ+0O0I+Jgdn0EuJ7UBDvcOro0uz5SXYXH6VZX7d7nqOlh+52GGKCG72vZQyFUHQy3AmskrZZ0ImmsyJ0V1/QzkpZm41wiaSlpoPK9pBo3Z7NtJp0zuQ661VW7Q+HreNh+tyEGqNn7OpShEIaxtXeBLawXkLaq3ge8vep65tR2Fmlr7u3AvlZ9pAN5byINyH4TsLyC2q4hNRcfJf0iXDJfXaThWe4D7gFeVoNaP0M6+PuO7IO7supageeSmth3kEaO3JN9Pmv1vs5TZ2HvqXs+mllO1asSZlZDDgYzy3EwmFmOg8HMchwMZpbjYDCzHAeDmeU4GMws5/8BscGhjGTC7xUAAAAASUVORK5CYII=",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "img_name = \"image_11_1101.png\"\n",
    "img = os.path.join(\"dataset/tianchi/round2/label/\", img_name)\n",
    "img = Image.open(img).resize((256, 256), Image.NEAREST)\n",
    "img = convert(img)\n",
    "cv2.imwrite(img_name, img)\n",
    "plt.imshow(img)"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "9ed70208bb8ef2fba028a67cdad176b6d0ad99a495b6a4fdc7ae902401be205f"
  },
  "kernelspec": {
   "display_name": "Python 3.7.11 64-bit ('torch-1.8.1': conda)",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.11"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
